package com.work.leecode.sort;

import java.util.Arrays;

/*
 *选择排序
 */
public class SelectSort {
    public static void main(String[] args) {
        int[] numbers = new int[]{2, 1, 5, 3, 2, 7, 4};

        for (int i = 0; i < numbers.length - 1; i++) {
            int min = numbers[i];
            int minIndex = i;
            for (int j = i + 1; j < numbers.length; j++) {
                if (numbers[j] < min) {
                    min = numbers[j];
                    minIndex = j;
                }
            }
            if (minIndex != i) {
                numbers[minIndex] = numbers[i];
                numbers[i] = min;
            }
        }
        System.out.println(Arrays.toString(numbers));
    }
}
